/*
 * Copyright (c) 2014, Institute for Pervasive Computing, ETH Zurich.
 * All rights reserved.
 *
 * Author: Andreas Dröscher <contiki@anticat.ch>
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the Institute nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */
/**
 * \addtogroup cc2538-examples
 * @{
 *
 * \defgroup cc2538-ecdsa-verify-test cc2538 ECDSA-Verify Test Project
 *
 *   ECDSA-Verify example for CC2538-based platforms
 *
 *   This example shows how ECDSA-Verify should be used. The example also verifies
 *   the ECDSA-Verify functionality.
 *
 * @{
 *
 * \file
 *     Example demonstrating ECDSA-Verify
 */
#include "contiki.h"
#include "dev/ecc-algorithm.h"
#include "dev/ecc-curve.h"
#include "lib/sha-256.h"
#include "sys/rtimer.h"
#include "sys/pt.h"

#include <string.h>
#include <stdio.h>
/*---------------------------------------------------------------------------*/
typedef struct {
  const uint8_t m[128]; /* Message */
  const uint8_t x[32];  /* Pub x */
  const uint8_t y[32];  /* Pub y */
  const uint8_t r[32];  /* Sig r */
  const uint8_t s[32];  /* Sig s */
  const bool result;    /* Expected result */
} test_data_t;
/*---------------------------------------------------------------------------*/
static inline
uint32_t
uint8x4_to_uint32(const uint8_t *field)
{
  return ((uint32_t)field[0] << 24)
         | ((uint32_t)field[1] << 16)
         | ((uint32_t)field[2] << 8)
         | ((uint32_t)field[3]);
}
/*---------------------------------------------------------------------------*/
static void
ec_uint8v_to_uint32v(uint32_t *result, const uint8_t *data, size_t size)
{
  /* `data` is expected to be encoded in big-endian */
  for(int i = (size / sizeof(uint32_t)) - 1; i >= 0; i--) {
    *result = uint8x4_to_uint32(&data[i * sizeof(uint32_t)]);
    result++;
  }
}
/*---------------------------------------------------------------------------*/
/* Test data from: https://csrc.nist.gov/Projects/
 * Cryptographic-Algorithm-Validation-Program/Digital-Signatures
 */
static const test_data_t tests[15] =
{
  {
    .m = { 0xe4, 0x79, 0x6d, 0xb5, 0xf7, 0x85, 0xf2, 0x07,
           0xaa, 0x30, 0xd3, 0x11, 0x69, 0x3b, 0x37, 0x02,
           0x82, 0x1d, 0xff, 0x11, 0x68, 0xfd, 0x2e, 0x04,
           0xc0, 0x83, 0x68, 0x25, 0xae, 0xfd, 0x85, 0x0d,
           0x9a, 0xa6, 0x03, 0x26, 0xd8, 0x8c, 0xde, 0x1a,
           0x23, 0xc7, 0x74, 0x53, 0x51, 0x39, 0x2c, 0xa2,
           0x28, 0x8d, 0x63, 0x2c, 0x26, 0x4f, 0x19, 0x7d,
           0x05, 0xcd, 0x42, 0x4a, 0x30, 0x33, 0x6c, 0x19,
           0xfd, 0x09, 0xbb, 0x22, 0x96, 0x54, 0xf0, 0x22,
           0x2f, 0xcb, 0x88, 0x1a, 0x4b, 0x35, 0xc2, 0x90,
           0xa0, 0x93, 0xac, 0x15, 0x9c, 0xe1, 0x34, 0x09,
           0x11, 0x1f, 0xf0, 0x35, 0x84, 0x11, 0x13, 0x3c,
           0x24, 0xf5, 0xb8, 0xe2, 0x09, 0x0d, 0x6d, 0xb6,
           0x55, 0x8a, 0xfc, 0x36, 0xf0, 0x6c, 0xa1, 0xf6,
           0xef, 0x77, 0x97, 0x85, 0xad, 0xba, 0x68, 0xdb,
           0x27, 0xa4, 0x09, 0x85, 0x9f, 0xc4, 0xc4, 0xa0 },
    .x = { 0x87, 0xf8, 0xf2, 0xb2, 0x18, 0xf4, 0x98, 0x45,
           0xf6, 0xf1, 0x0e, 0xec, 0x38, 0x77, 0x13, 0x62,
           0x69, 0xf5, 0xc1, 0xa5, 0x47, 0x36, 0xdb, 0xdf,
           0x69, 0xf8, 0x99, 0x40, 0xca, 0xd4, 0x15, 0x55 },
    .y = { 0xe1, 0x5f, 0x36, 0x90, 0x36, 0xf4, 0x98, 0x42,
           0xfa, 0xc7, 0xa8, 0x6c, 0x8a, 0x2b, 0x05, 0x57,
           0x60, 0x97, 0x76, 0x81, 0x44, 0x48, 0xb8, 0xf5,
           0xe8, 0x4a, 0xa9, 0xf4, 0x39, 0x52, 0x05, 0xe9 },
    .r = { 0xd1, 0x9f, 0xf4, 0x8b, 0x32, 0x49, 0x15, 0x57,
           0x64, 0x16, 0x09, 0x7d, 0x25, 0x44, 0xf7, 0xcb,
           0xdf, 0x87, 0x68, 0xb1, 0x45, 0x4a, 0xd2, 0x0e,
           0x0b, 0xaa, 0xc5, 0x0e, 0x21, 0x1f, 0x23, 0xb0 },
    .s = { 0xa3, 0xe8, 0x1e, 0x59, 0x31, 0x1c, 0xdf, 0xff,
           0x2d, 0x47, 0x84, 0x94, 0x9f, 0x7a, 0x2c, 0xb5,
           0x0b, 0xa6, 0xc3, 0xa9, 0x1f, 0xa5, 0x47, 0x10,
           0x56, 0x8e, 0x61, 0xac, 0xa3, 0xe8, 0x47, 0xc6 },
    .result = false /*F (3 - S changed) */
  },

  {
    .m = { 0x06, 0x9a, 0x6e, 0x6b, 0x93, 0xdf, 0xee, 0x6d,
           0xf6, 0xef, 0x69, 0x97, 0xcd, 0x80, 0xdd, 0x21,
           0x82, 0xc3, 0x66, 0x53, 0xce, 0xf1, 0x0c, 0x65,
           0x5d, 0x52, 0x45, 0x85, 0x65, 0x54, 0x62, 0xd6,
           0x83, 0x87, 0x7f, 0x95, 0xec, 0xc6, 0xd6, 0xc8,
           0x16, 0x23, 0xd8, 0xfa, 0xc4, 0xe9, 0x00, 0xed,
           0x00, 0x19, 0x96, 0x40, 0x94, 0xe7, 0xde, 0x91,
           0xf1, 0x48, 0x19, 0x89, 0xae, 0x18, 0x73, 0x00,
           0x45, 0x65, 0x78, 0x9c, 0xbf, 0x5d, 0xc5, 0x6c,
           0x62, 0xae, 0xdc, 0x63, 0xf6, 0x2f, 0x3b, 0x89,
           0x4c, 0x9c, 0x6f, 0x77, 0x88, 0xc8, 0xec, 0xaa,
           0xdc, 0x9b, 0xd0, 0xe8, 0x1a, 0xd9, 0x1b, 0x2b,
           0x35, 0x69, 0xea, 0x12, 0x26, 0x0e, 0x93, 0x92,
           0x4f, 0xdd, 0xdd, 0x39, 0x72, 0xaf, 0x52, 0x73,
           0x19, 0x8f, 0x5e, 0xfd, 0xa0, 0x74, 0x62, 0x19,
           0x47, 0x50, 0x17, 0x55, 0x76, 0x16, 0x17, 0x0e },
    .x = { 0x5c, 0xf0, 0x2a, 0x00, 0xd2, 0x05, 0xbd, 0xfe,
           0xe2, 0x01, 0x6f, 0x74, 0x21, 0x80, 0x7f, 0xc3,
           0x8a, 0xe6, 0x9e, 0x6b, 0x7c, 0xcd, 0x06, 0x4e,
           0xe6, 0x89, 0xfc, 0x1a, 0x94, 0xa9, 0xf7, 0xd2 },
    .y = { 0xec, 0x53, 0x0c, 0xe3, 0xcc, 0x5c, 0x9d, 0x1a,
           0xf4, 0x63, 0xf2, 0x64, 0xd6, 0x85, 0xaf, 0xe2,
           0xb4, 0xdb, 0x4b, 0x58, 0x28, 0xd7, 0xe6, 0x1b,
           0x74, 0x89, 0x30, 0xf3, 0xce, 0x62, 0x2a, 0x85 },
    .r = { 0xdc, 0x23, 0xd1, 0x30, 0xc6, 0x11, 0x7f, 0xb5,
           0x75, 0x12, 0x01, 0x45, 0x5e, 0x99, 0xf3, 0x6f,
           0x59, 0xab, 0xa1, 0xa6, 0xa2, 0x1c, 0xf2, 0xd0,
           0xe7, 0x48, 0x1a, 0x97, 0x45, 0x1d, 0x66, 0x93 },
    .s = { 0xd6, 0xce, 0x77, 0x08, 0xc1, 0x8d, 0xbf, 0x35,
           0xd4, 0xf8, 0xaa, 0x72, 0x40, 0x92, 0x2d, 0xc6,
           0x82, 0x3f, 0x2e, 0x70, 0x58, 0xcb, 0xc1, 0x48,
           0x4f, 0xca, 0xd1, 0x59, 0x9d, 0xb5, 0x01, 0x8c },
    .result = false /*F (2 - R changed) */
  },

  {
    .m = { 0xdf, 0x04, 0xa3, 0x46, 0xcf, 0x4d, 0x0e, 0x33,
           0x1a, 0x6d, 0xb7, 0x8c, 0xca, 0x2d, 0x45, 0x6d,
           0x31, 0xb0, 0xa0, 0x00, 0xaa, 0x51, 0x44, 0x1d,
           0xef, 0xdb, 0x97, 0xbb, 0xeb, 0x20, 0xb9, 0x4d,
           0x8d, 0x74, 0x64, 0x29, 0xa3, 0x93, 0xba, 0x88,
           0x84, 0x0d, 0x66, 0x16, 0x15, 0xe0, 0x7d, 0xef,
           0x61, 0x5a, 0x34, 0x2a, 0xbe, 0xdf, 0xa4, 0xce,
           0x91, 0x2e, 0x56, 0x2a, 0xf7, 0x14, 0x95, 0x98,
           0x96, 0x85, 0x8a, 0xf8, 0x17, 0x31, 0x7a, 0x84,
           0x0d, 0xcf, 0xf8, 0x5a, 0x05, 0x7b, 0xb9, 0x1a,
           0x3c, 0x2b, 0xf9, 0x01, 0x05, 0x50, 0x03, 0x62,
           0x75, 0x4a, 0x6d, 0xd3, 0x21, 0xcd, 0xd8, 0x61,
           0x28, 0xcf, 0xc5, 0xf0, 0x46, 0x67, 0xb5, 0x7a,
           0xa7, 0x8c, 0x11, 0x24, 0x11, 0xe4, 0x2d, 0xa3,
           0x04, 0xf1, 0x01, 0x2d, 0x48, 0xcd, 0x6a, 0x70,
           0x52, 0xd7, 0xde, 0x44, 0xeb, 0xcc, 0x01, 0xde },
    .x = { 0x2d, 0xdf, 0xd1, 0x45, 0x76, 0x78, 0x83, 0xff,
           0xbb, 0x0a, 0xc0, 0x03, 0xab, 0x4a, 0x44, 0x34,
           0x6d, 0x08, 0xfa, 0x25, 0x70, 0xb3, 0x12, 0x0d,
           0xcc, 0xe9, 0x45, 0x62, 0x42, 0x22, 0x44, 0xcb },
    .y = { 0x5f, 0x70, 0xc7, 0xd1, 0x1a, 0xc2, 0xb7, 0xa4,
           0x35, 0xcc, 0xfb, 0xba, 0xe0, 0x2c, 0x3d, 0xf1,
           0xea, 0x6b, 0x53, 0x2c, 0xc0, 0xe9, 0xdb, 0x74,
           0xf9, 0x3f, 0xff, 0xca, 0x7c, 0x6f, 0x9a, 0x64 },
    .r = { 0x99, 0x13, 0x11, 0x1c, 0xff, 0x6f, 0x20, 0xc5,
           0xbf, 0x45, 0x3a, 0x99, 0xcd, 0x2c, 0x20, 0x19,
           0xa4, 0xe7, 0x49, 0xa4, 0x97, 0x24, 0xa0, 0x87,
           0x74, 0xd1, 0x4e, 0x4c, 0x11, 0x3e, 0xdd, 0xa8 },
    .s = { 0x94, 0x67, 0xcd, 0x4c, 0xd2, 0x1e, 0xcb, 0x56,
           0xb0, 0xca, 0xb0, 0xa9, 0xa4, 0x53, 0xb4, 0x33,
           0x86, 0x84, 0x54, 0x59, 0x12, 0x7a, 0x95, 0x24,
           0x21, 0xf5, 0xc6, 0x38, 0x28, 0x66, 0xc5, 0xcc },
    .result = false /*F (4 - Q changed) */
  },

  {
    .m = { 0xe1, 0x13, 0x0a, 0xf6, 0xa3, 0x8c, 0xcb, 0x41,
           0x2a, 0x9c, 0x8d, 0x13, 0xe1, 0x5d, 0xbf, 0xc9,
           0xe6, 0x9a, 0x16, 0x38, 0x5a, 0xf3, 0xc3, 0xf1,
           0xe5, 0xda, 0x95, 0x4f, 0xd5, 0xe7, 0xc4, 0x5f,
           0xd7, 0x5e, 0x2b, 0x8c, 0x36, 0x69, 0x92, 0x28,
           0xe9, 0x28, 0x40, 0xc0, 0x56, 0x2f, 0xbf, 0x37,
           0x72, 0xf0, 0x7e, 0x17, 0xf1, 0xad, 0xd5, 0x65,
           0x88, 0xdd, 0x45, 0xf7, 0x45, 0x0e, 0x12, 0x17,
           0xad, 0x23, 0x99, 0x22, 0xdd, 0x9c, 0x32, 0x69,
           0x5d, 0xc7, 0x1f, 0xf2, 0x42, 0x4c, 0xa0, 0xde,
           0xc1, 0x32, 0x1a, 0xa4, 0x70, 0x64, 0xa0, 0x44,
           0xb7, 0xfe, 0x3c, 0x2b, 0x97, 0xd0, 0x3c, 0xe4,
           0x70, 0xa5, 0x92, 0x30, 0x4c, 0x5e, 0xf2, 0x1e,
           0xed, 0x9f, 0x93, 0xda, 0x56, 0xbb, 0x23, 0x2d,
           0x1e, 0xeb, 0x00, 0x35, 0xf9, 0xbf, 0x0d, 0xfa,
           0xfd, 0xcc, 0x46, 0x06, 0x27, 0x2b, 0x20, 0xa3 },
    .x = { 0xe4, 0x24, 0xdc, 0x61, 0xd4, 0xbb, 0x3c, 0xb7,
           0xef, 0x43, 0x44, 0xa7, 0xf8, 0x95, 0x7a, 0x0c,
           0x51, 0x34, 0xe1, 0x6f, 0x7a, 0x67, 0xc0, 0x74,
           0xf8, 0x2e, 0x6e, 0x12, 0xf4, 0x9a, 0xbf, 0x3c },
    .y = { 0x97, 0x0e, 0xed, 0x7a, 0xa2, 0xbc, 0x48, 0x65,
           0x15, 0x45, 0x94, 0x9d, 0xe1, 0xdd, 0xda, 0xf0,
           0x12, 0x7e, 0x59, 0x65, 0xac, 0x85, 0xd1, 0x24,
           0x3d, 0x6f, 0x60, 0xe7, 0xdf, 0xae, 0xe9, 0x27 },
    .r = { 0xbf, 0x96, 0xb9, 0x9a, 0xa4, 0x9c, 0x70, 0x5c,
           0x91, 0x0b, 0xe3, 0x31, 0x42, 0x01, 0x7c, 0x64,
           0x2f, 0xf5, 0x40, 0xc7, 0x63, 0x49, 0xb9, 0xda,
           0xb7, 0x2f, 0x98, 0x1f, 0xd9, 0x34, 0x7f, 0x4f },
    .s = { 0x17, 0xc5, 0x50, 0x95, 0x81, 0x90, 0x89, 0xc2,
           0xe0, 0x3b, 0x9c, 0xd4, 0x15, 0xab, 0xdf, 0x12,
           0x44, 0x4e, 0x32, 0x30, 0x75, 0xd9, 0x8f, 0x31,
           0x92, 0x0b, 0x9e, 0x0f, 0x57, 0xec, 0x87, 0x1c },
    .result = true /*P (0 ) */
  },

  {
    .m = { 0x73, 0xc5, 0xf6, 0xa6, 0x74, 0x56, 0xae, 0x48,
           0x20, 0x9b, 0x5f, 0x85, 0xd1, 0xe7, 0xde, 0x77,
           0x58, 0xbf, 0x23, 0x53, 0x00, 0xc6, 0xae, 0x2b,
           0xdc, 0xeb, 0x1d, 0xcb, 0x27, 0xa7, 0x73, 0x0f,
           0xb6, 0x8c, 0x95, 0x0b, 0x7f, 0xca, 0xda, 0x0e,
           0xcc, 0x46, 0x61, 0xd3, 0x57, 0x82, 0x30, 0xf2,
           0x25, 0xa8, 0x75, 0xe6, 0x9a, 0xaa, 0x17, 0xf1,
           0xe7, 0x1c, 0x6b, 0xe5, 0xc8, 0x31, 0xf2, 0x26,
           0x63, 0xba, 0xc6, 0x3d, 0x0c, 0x7a, 0x96, 0x35,
           0xed, 0xb0, 0x04, 0x3f, 0xf8, 0xc6, 0xf2, 0x64,
           0x70, 0xf0, 0x2a, 0x7b, 0xc5, 0x65, 0x56, 0xf1,
           0x43, 0x7f, 0x06, 0xdf, 0xa2, 0x7b, 0x48, 0x7a,
           0x6c, 0x42, 0x90, 0xd8, 0xba, 0xd3, 0x8d, 0x48,
           0x79, 0xb3, 0x34, 0xe3, 0x41, 0xba, 0x09, 0x2d,
           0xde, 0x4e, 0x4a, 0xe6, 0x94, 0xa9, 0xc0, 0x93,
           0x02, 0xe2, 0xdb, 0xf4, 0x43, 0x58, 0x1c, 0x08 },
    .x = { 0xe0, 0xfc, 0x6a, 0x6f, 0x50, 0xe1, 0xc5, 0x74,
           0x75, 0x67, 0x3e, 0xe5, 0x4e, 0x3a, 0x57, 0xf9,
           0xa4, 0x9f, 0x33, 0x28, 0xe7, 0x43, 0xbf, 0x52,
           0xf3, 0x35, 0xe3, 0xee, 0xaa, 0x3d, 0x28, 0x64 },
    .y = { 0x7f, 0x59, 0xd6, 0x89, 0xc9, 0x1e, 0x46, 0x36,
           0x07, 0xd9, 0x19, 0x4d, 0x99, 0xfa, 0xf3, 0x16,
           0xe2, 0x54, 0x32, 0x87, 0x08, 0x16, 0xdd, 0xe6,
           0x3f, 0x5d, 0x4b, 0x37, 0x3f, 0x12, 0xf2, 0x2a },
    .r = { 0x1d, 0x75, 0x83, 0x0c, 0xd3, 0x6f, 0x4c, 0x9a,
           0xa1, 0x81, 0xb2, 0xc4, 0x22, 0x1e, 0x87, 0xf1,
           0x76, 0xb7, 0xf0, 0x5b, 0x7c, 0x87, 0x82, 0x4e,
           0x82, 0xe3, 0x96, 0xc8, 0x83, 0x15, 0xc4, 0x07 },
    .s = { 0xcb, 0x2a, 0xcb, 0x01, 0xda, 0xc9, 0x6e, 0xfc,
           0x53, 0xa3, 0x2d, 0x4a, 0x0d, 0x85, 0xd0, 0xc2,
           0xe4, 0x89, 0x55, 0x21, 0x47, 0x83, 0xec, 0xf5,
           0x0a, 0x4f, 0x04, 0x14, 0xa3, 0x19, 0xc0, 0x5a },
    .result = true /*P (0 ) */
  },

  {
    .m = { 0x66, 0x60, 0x36, 0xd9, 0xb4, 0xa2, 0x42, 0x6e,
           0xd6, 0x58, 0x5a, 0x4e, 0x0f, 0xd9, 0x31, 0xa8,
           0x76, 0x14, 0x51, 0xd2, 0x9a, 0xb0, 0x4b, 0xd7,
           0xdc, 0x6d, 0x0c, 0x5b, 0x9e, 0x38, 0xe6, 0xc2,
           0xb2, 0x63, 0xff, 0x6c, 0xb8, 0x37, 0xbd, 0x04,
           0x39, 0x9d, 0xe3, 0xd7, 0x57, 0xc6, 0xc7, 0x00,
           0x5f, 0x6d, 0x7a, 0x98, 0x70, 0x63, 0xcf, 0x6d,
           0x7e, 0x8c, 0xb3, 0x8a, 0x4b, 0xf0, 0xd7, 0x4a,
           0x28, 0x25, 0x72, 0xbd, 0x01, 0xd0, 0xf4, 0x1e,
           0x3f, 0xd0, 0x66, 0xe3, 0x02, 0x15, 0x75, 0xf0,
           0xfa, 0x04, 0xf2, 0x7b, 0x70, 0x0d, 0x5b, 0x7d,
           0xdd, 0xdf, 0x50, 0x96, 0x59, 0x93, 0xc3, 0xf9,
           0xc7, 0x11, 0x8e, 0xd7, 0x88, 0x88, 0xda, 0x7c,
           0xb2, 0x21, 0x84, 0x9b, 0x32, 0x60, 0x59, 0x2b,
           0x8e, 0x63, 0x2d, 0x7c, 0x51, 0xe9, 0x35, 0xa0,
           0xce, 0xae, 0x15, 0x20, 0x7b, 0xed, 0xd5, 0x48 },
    .x = { 0xa8, 0x49, 0xbe, 0xf5, 0x75, 0xca, 0xc3, 0xc6,
           0x92, 0x0f, 0xbc, 0xe6, 0x75, 0xc3, 0xb7, 0x87,
           0x13, 0x62, 0x09, 0xf8, 0x55, 0xde, 0x19, 0xff,
           0xe2, 0xe8, 0xd2, 0x9b, 0x31, 0xa5, 0xad, 0x86 },
    .y = { 0xbf, 0x5f, 0xe4, 0xf7, 0x85, 0x8f, 0x9b, 0x80,
           0x5b, 0xd8, 0xdc, 0xc0, 0x5a, 0xd5, 0xe7, 0xfb,
           0x88, 0x9d, 0xe2, 0xf8, 0x22, 0xf3, 0xd8, 0xb4,
           0x16, 0x94, 0xe6, 0xc5, 0x5c, 0x16, 0xb4, 0x71 },
    .r = { 0x25, 0xac, 0xc3, 0xaa, 0x9d, 0x9e, 0x84, 0xc7,
           0xab, 0xf0, 0x8f, 0x73, 0xfa, 0x41, 0x95, 0xac,
           0xc5, 0x06, 0x49, 0x1d, 0x6f, 0xc3, 0x7c, 0xb9,
           0x07, 0x45, 0x28, 0xa7, 0xdb, 0x87, 0xb9, 0xd6 },
    .s = { 0x9b, 0x21, 0xd5, 0xb5, 0x25, 0x9e, 0xd3, 0xf2,
           0xef, 0x07, 0xdf, 0xec, 0x6c, 0xc9, 0x0d, 0x3a,
           0x37, 0x85, 0x5d, 0x1c, 0xe1, 0x22, 0xa8, 0x5b,
           0xa6, 0xa3, 0x33, 0xf3, 0x07, 0xd3, 0x15, 0x37 },
    .result = false /*F (2 - R changed) */
  },

  {
    .m = { 0x7e, 0x80, 0x43, 0x6b, 0xce, 0x57, 0x33, 0x9c,
           0xe8, 0xda, 0x1b, 0x56, 0x60, 0x14, 0x9a, 0x20,
           0x24, 0x0b, 0x14, 0x6d, 0x10, 0x8d, 0xee, 0xf3,
           0xec, 0x5d, 0xa4, 0xae, 0x25, 0x6f, 0x8f, 0x89,
           0x4e, 0xdc, 0xbb, 0xc5, 0x7b, 0x34, 0xce, 0x37,
           0x08, 0x9c, 0x0d, 0xaa, 0x17, 0xf0, 0xc4, 0x6c,
           0xd8, 0x2b, 0x5a, 0x15, 0x99, 0x31, 0x4f, 0xd7,
           0x9d, 0x2f, 0xd2, 0xf4, 0x46, 0xbd, 0x5a, 0x25,
           0xb8, 0xe3, 0x2f, 0xcf, 0x05, 0xb7, 0x6d, 0x64,
           0x45, 0x73, 0xa6, 0xdf, 0x4a, 0xd1, 0xdf, 0xea,
           0x70, 0x7b, 0x47, 0x9d, 0x97, 0x23, 0x7a, 0x34,
           0x6f, 0x1e, 0xc6, 0x32, 0xea, 0x56, 0x60, 0xef,
           0xb5, 0x7e, 0x87, 0x17, 0xa8, 0x62, 0x8d, 0x7f,
           0x82, 0xaf, 0x50, 0xa4, 0xe8, 0x4b, 0x11, 0xf2,
           0x1b, 0xdf, 0xf6, 0x83, 0x91, 0x96, 0xa8, 0x80,
           0xae, 0x20, 0xb2, 0xa0, 0x91, 0x8d, 0x58, 0xcd },
    .x = { 0x3d, 0xfb, 0x6f, 0x40, 0xf2, 0x47, 0x1b, 0x29,
           0xb7, 0x7f, 0xdc, 0xcb, 0xa7, 0x2d, 0x37, 0xc2,
           0x1b, 0xba, 0x01, 0x9e, 0xfa, 0x40, 0xc1, 0xc8,
           0xf9, 0x1e, 0xc4, 0x05, 0xd7, 0xdc, 0xc5, 0xdf },
    .y = { 0xf2, 0x2f, 0x95, 0x3f, 0x1e, 0x39, 0x5a, 0x52,
           0xea, 0xd7, 0xf3, 0xae, 0x3f, 0xc4, 0x74, 0x51,
           0xb4, 0x38, 0x11, 0x7b, 0x1e, 0x04, 0xd6, 0x13,
           0xbc, 0x85, 0x55, 0xb7, 0xd6, 0xe6, 0xd1, 0xbb },
    .r = { 0x54, 0x88, 0x86, 0x27, 0x8e, 0x5e, 0xc2, 0x6b,
           0xed, 0x81, 0x1d, 0xbb, 0x72, 0xdb, 0x1e, 0x15,
           0x4b, 0x6f, 0x17, 0xbe, 0x70, 0xde, 0xb1, 0xb2,
           0x10, 0x10, 0x7d, 0xec, 0xb1, 0xec, 0x2a, 0x5a },
    .s = { 0xe9, 0x3b, 0xfe, 0xbd, 0x2f, 0x14, 0xf3, 0xd8,
           0x27, 0xca, 0x32, 0xb4, 0x64, 0xbe, 0x6e, 0x69,
           0x18, 0x7f, 0x5e, 0xdb, 0xd5, 0x2d, 0xef, 0x4f,
           0x96, 0x59, 0x9c, 0x37, 0xd5, 0x8e, 0xee, 0x75 },
    .result = false /*F (4 - Q changed) */
  },

  {
    .m = { 0x16, 0x69, 0xbf, 0xb6, 0x57, 0xfd, 0xc6, 0x2c,
           0x3d, 0xdd, 0x63, 0x26, 0x97, 0x87, 0xfc, 0x1c,
           0x96, 0x9f, 0x18, 0x50, 0xfb, 0x04, 0xc9, 0x33,
           0xdd, 0xa0, 0x63, 0xef, 0x74, 0xa5, 0x6c, 0xe1,
           0x3e, 0x3a, 0x64, 0x97, 0x00, 0x82, 0x0f, 0x00,
           0x61, 0xef, 0xab, 0xf8, 0x49, 0xa8, 0x5d, 0x47,
           0x43, 0x26, 0xc8, 0xa5, 0x41, 0xd9, 0x98, 0x30,
           0xee, 0xa8, 0x13, 0x1e, 0xae, 0xa5, 0x84, 0xf2,
           0x2d, 0x88, 0xc3, 0x53, 0x96, 0x5d, 0xab, 0xcd,
           0xc4, 0xbf, 0x6b, 0x55, 0x94, 0x9f, 0xd5, 0x29,
           0x50, 0x7d, 0xfb, 0x80, 0x3a, 0xb6, 0xb4, 0x80,
           0xcd, 0x73, 0xca, 0x0b, 0xa0, 0x0c, 0xa1, 0x9c,
           0x43, 0x88, 0x49, 0xe2, 0xce, 0xa2, 0x62, 0xa1,
           0xc5, 0x7d, 0x8f, 0x81, 0xcd, 0x25, 0x7f, 0xb5,
           0x8e, 0x19, 0xde, 0xc7, 0x90, 0x4d, 0xa9, 0x7d,
           0x83, 0x86, 0xe8, 0x7b, 0x84, 0x94, 0x81, 0x69 },
    .x = { 0x69, 0xb7, 0x66, 0x70, 0x56, 0xe1, 0xe1, 0x1d,
           0x6c, 0xaf, 0x6e, 0x45, 0x64, 0x3f, 0x8b, 0x21,
           0xe7, 0xa4, 0xbe, 0xbd, 0xa4, 0x63, 0xc7, 0xfd,
           0xbc, 0x13, 0xbc, 0x98, 0xef, 0xbd, 0x02, 0x14 },
    .y = { 0xd3, 0xf9, 0xb1, 0x2e, 0xb4, 0x6c, 0x7c, 0x6f,
           0xda, 0x0d, 0xa3, 0xfc, 0x85, 0xbc, 0x1f, 0xd8,
           0x31, 0x55, 0x7f, 0x9a, 0xbc, 0x90, 0x2a, 0x3b,
           0xe3, 0xcb, 0x3e, 0x8b, 0xe7, 0xd1, 0xaa, 0x2f },
    .r = { 0x28, 0x8f, 0x7a, 0x1c, 0xd3, 0x91, 0x84, 0x2c,
           0xce, 0x21, 0xf0, 0x0e, 0x6f, 0x15, 0x47, 0x1c,
           0x04, 0xdc, 0x18, 0x2f, 0xe4, 0xb1, 0x4d, 0x92,
           0xdc, 0x18, 0x91, 0x08, 0x79, 0x79, 0x97, 0x90 },
    .s = { 0x24, 0x7b, 0x3c, 0x4e, 0x89, 0xa3, 0xbc, 0xad,
           0xfe, 0xa7, 0x3c, 0x7b, 0xfd, 0x36, 0x1d, 0xef,
           0x43, 0x71, 0x5f, 0xa3, 0x82, 0xb8, 0xc3, 0xed,
           0xf4, 0xae, 0x15, 0xd6, 0xe5, 0x5e, 0x99, 0x79 },
    .result = false /*F (1 - Message changed) */
  },

  {
    .m = { 0x3f, 0xe6, 0x0d, 0xd9, 0xad, 0x6c, 0xac, 0xcf,
           0x5a, 0x6f, 0x58, 0x3b, 0x3a, 0xe6, 0x59, 0x53,
           0x56, 0x34, 0x46, 0xc4, 0x51, 0x0b, 0x70, 0xda,
           0x11, 0x5f, 0xfa, 0xa0, 0xba, 0x04, 0xc0, 0x76,
           0x11, 0x5c, 0x70, 0x43, 0xab, 0x87, 0x33, 0x40,
           0x3c, 0xd6, 0x9c, 0x7d, 0x14, 0xc2, 0x12, 0xc6,
           0x55, 0xc0, 0x7b, 0x43, 0xa7, 0xc7, 0x1b, 0x9a,
           0x4c, 0xff, 0xe2, 0x2c, 0x26, 0x84, 0x78, 0x8e,
           0xc6, 0x87, 0x0d, 0xc2, 0x01, 0x3f, 0x26, 0x91,
           0x72, 0xc8, 0x22, 0x25, 0x6f, 0x9e, 0x7c, 0xc6,
           0x74, 0x79, 0x1b, 0xf2, 0xd8, 0x48, 0x6c, 0x0f,
           0x56, 0x84, 0x28, 0x3e, 0x16, 0x49, 0x57, 0x6e,
           0xfc, 0x98, 0x2e, 0xde, 0x17, 0xc7, 0xb7, 0x4b,
           0x21, 0x47, 0x54, 0xd7, 0x04, 0x02, 0xfb, 0x4b,
           0xb4, 0x5a, 0xd0, 0x86, 0xcf, 0x2c, 0xf7, 0x6b,
           0x3d, 0x63, 0xf7, 0xfc, 0xe3, 0x9a, 0xc9, 0x70 },
    .x = { 0xbf, 0x02, 0xcb, 0xcf, 0x6d, 0x8c, 0xc2, 0x6e,
           0x91, 0x76, 0x6d, 0x8a, 0xf0, 0xb1, 0x64, 0xfc,
           0x59, 0x68, 0x53, 0x5e, 0x84, 0xc1, 0x58, 0xeb,
           0x3b, 0xc4, 0xe2, 0xd7, 0x9c, 0x3c, 0xc6, 0x82 },
    .y = { 0x06, 0x9b, 0xa6, 0xcb, 0x06, 0xb4, 0x9d, 0x60,
           0x81, 0x20, 0x66, 0xaf, 0xa1, 0x6e, 0xcf, 0x7b,
           0x51, 0x35, 0x2f, 0x2c, 0x03, 0xbd, 0x93, 0xec,
           0x22, 0x08, 0x22, 0xb1, 0xf3, 0xdf, 0xba, 0x03 },
    .r = { 0xf5, 0xac, 0xb0, 0x6c, 0x59, 0xc2, 0xb4, 0x92,
           0x7f, 0xb8, 0x52, 0xfa, 0xa0, 0x7f, 0xaf, 0x4b,
           0x18, 0x52, 0xbb, 0xb5, 0xd0, 0x68, 0x40, 0x93,
           0x5e, 0x84, 0x9c, 0x4d, 0x29, 0x3d, 0x1b, 0xad },
    .s = { 0x04, 0x9d, 0xab, 0x79, 0xc8, 0x9c, 0xc0, 0x2f,
           0x14, 0x84, 0xc4, 0x37, 0xf5, 0x23, 0xe0, 0x80,
           0xa7, 0x5f, 0x13, 0x49, 0x17, 0xfd, 0xa7, 0x52,
           0xf2, 0xd5, 0xca, 0x39, 0x7a, 0xdd, 0xfe, 0x5d },
    .result = false /*F (3 - S changed) */
  },

  {
    .m = { 0x98, 0x3a, 0x71, 0xb9, 0x99, 0x4d, 0x95, 0xe8,
           0x76, 0xd8, 0x4d, 0x28, 0x94, 0x6a, 0x04, 0x1f,
           0x8f, 0x0a, 0x3f, 0x54, 0x4c, 0xfc, 0xc0, 0x55,
           0x49, 0x65, 0x80, 0xf1, 0xdf, 0xd4, 0xe3, 0x12,
           0xa2, 0xad, 0x41, 0x8f, 0xe6, 0x9d, 0xbc, 0x61,
           0xdb, 0x23, 0x0c, 0xc0, 0xc0, 0xed, 0x97, 0xe3,
           0x60, 0xab, 0xab, 0x7d, 0x6f, 0xf4, 0xb8, 0x1e,
           0xe9, 0x70, 0xa7, 0xe9, 0x74, 0x66, 0xac, 0xfd,
           0x96, 0x44, 0xf8, 0x28, 0xff, 0xec, 0x53, 0x8a,
           0xbc, 0x38, 0x3d, 0x0e, 0x92, 0x32, 0x6d, 0x1c,
           0x88, 0xc5, 0x5e, 0x1f, 0x46, 0xa6, 0x68, 0xa0,
           0x39, 0xbe, 0xaa, 0x1b, 0xe6, 0x31, 0xa8, 0x91,
           0x29, 0x93, 0x8c, 0x00, 0xa8, 0x1a, 0x3a, 0xe4,
           0x6d, 0x4a, 0xec, 0xbf, 0x97, 0x07, 0xf7, 0x64,
           0xdb, 0xac, 0xce, 0xa3, 0xef, 0x76, 0x65, 0xe4,
           0xc4, 0x30, 0x7f, 0xa0, 0xb0, 0xa3, 0x07, 0x5c },
    .x = { 0x22, 0x4a, 0x4d, 0x65, 0xb9, 0x58, 0xf6, 0xd6,
           0xaf, 0xb2, 0x90, 0x48, 0x63, 0xef, 0xd2, 0xa7,
           0x34, 0xb3, 0x17, 0x98, 0x88, 0x48, 0x01, 0xfc,
           0xab, 0x5a, 0x59, 0x0f, 0x4d, 0x6d, 0xa9, 0xde },
    .y = { 0x17, 0x8d, 0x51, 0xfd, 0xda, 0xda, 0x62, 0x80,
           0x6f, 0x09, 0x7a, 0xa6, 0x15, 0xd3, 0x3b, 0x8f,
           0x24, 0x04, 0xe6, 0xb1, 0x47, 0x9f, 0x5f, 0xd4,
           0x85, 0x9d, 0x59, 0x57, 0x34, 0xd6, 0xd2, 0xb9 },
    .r = { 0x87, 0xb9, 0x3e, 0xe2, 0xfe, 0xcf, 0xda, 0x54,
           0xde, 0xb8, 0xdf, 0xf8, 0xe4, 0x26, 0xf3, 0xc7,
           0x2c, 0x88, 0x64, 0x99, 0x1f, 0x8e, 0xc2, 0xb3,
           0x20, 0x5b, 0xb3, 0xb4, 0x16, 0xde, 0x93, 0xd2 },
    .s = { 0x40, 0x44, 0xa2, 0x4d, 0xf8, 0x5b, 0xe0, 0xcc,
           0x76, 0xf2, 0x1a, 0x44, 0x30, 0xb7, 0x5b, 0x8e,
           0x77, 0xb9, 0x32, 0xa8, 0x7f, 0x51, 0xe4, 0xec,
           0xcb, 0xc4, 0x5c, 0x26, 0x3e, 0xbf, 0x8f, 0x66 },
    .result = false /*F (2 - R changed) */
  },

  {
    .m = { 0x4a, 0x8c, 0x07, 0x1a, 0xc4, 0xfd, 0x0d, 0x52,
           0xfa, 0xa4, 0x07, 0xb0, 0xfe, 0x5d, 0xab, 0x75,
           0x9f, 0x73, 0x94, 0xa5, 0x83, 0x21, 0x27, 0xf2,
           0xa3, 0x49, 0x8f, 0x34, 0xaa, 0xc2, 0x87, 0x33,
           0x9e, 0x04, 0x3b, 0x4f, 0xfa, 0x79, 0x52, 0x8f,
           0xaf, 0x19, 0x9d, 0xc9, 0x17, 0xf7, 0xb0, 0x66,
           0xad, 0x65, 0x50, 0x5d, 0xab, 0x0e, 0x11, 0xe6,
           0x94, 0x85, 0x15, 0x05, 0x2c, 0xe2, 0x0c, 0xfd,
           0xb8, 0x92, 0xff, 0xb8, 0xaa, 0x9b, 0xf3, 0xf1,
           0xaa, 0x5b, 0xe3, 0x0a, 0x5b, 0xbe, 0x85, 0x82,
           0x3b, 0xdd, 0xf7, 0x0b, 0x39, 0xfd, 0x7e, 0xbd,
           0x4a, 0x93, 0xa2, 0xf7, 0x54, 0x72, 0xc1, 0xd4,
           0xf6, 0x06, 0x24, 0x7a, 0x98, 0x21, 0xf1, 0xa8,
           0xc4, 0x5a, 0x6c, 0xb8, 0x05, 0x45, 0xde, 0x2e,
           0x0c, 0x6c, 0x01, 0x74, 0xe2, 0x39, 0x20, 0x88,
           0xc7, 0x54, 0xe9, 0xc8, 0x44, 0x3e, 0xb5, 0xaf },
    .x = { 0x43, 0x69, 0x1c, 0x77, 0x95, 0xa5, 0x7e, 0xad,
           0x8c, 0x5c, 0x68, 0x53, 0x6f, 0xe9, 0x34, 0x53,
           0x8d, 0x46, 0xf1, 0x28, 0x89, 0x68, 0x0a, 0x9c,
           0xb6, 0xd0, 0x55, 0xa0, 0x66, 0x22, 0x83, 0x69 },
    .y = { 0xf8, 0x79, 0x01, 0x10, 0xb3, 0xc3, 0xb2, 0x81,
           0xaa, 0x1e, 0xae, 0x03, 0x7d, 0x4f, 0x12, 0x34,
           0xaf, 0xf5, 0x87, 0xd9, 0x03, 0xd9, 0x3b, 0xa3,
           0xaf, 0x22, 0x5c, 0x27, 0xdd, 0xc9, 0xcc, 0xac },
    .r = { 0x8a, 0xcd, 0x62, 0xe8, 0xc2, 0x62, 0xfa, 0x50,
           0xdd, 0x98, 0x40, 0x48, 0x09, 0x69, 0xf4, 0xef,
           0x70, 0xf2, 0x18, 0xeb, 0xf8, 0xef, 0x95, 0x84,
           0xf1, 0x99, 0x03, 0x11, 0x32, 0xc6, 0xb1, 0xce },
    .s = { 0xcf, 0xca, 0x7e, 0xd3, 0xd4, 0x34, 0x7f, 0xb2,
           0xa2, 0x9e, 0x52, 0x6b, 0x43, 0xc3, 0x48, 0xae,
           0x1c, 0xe6, 0xc6, 0x0d, 0x44, 0xf3, 0x19, 0x1b,
           0x6d, 0x8e, 0xa3, 0xa2, 0xd9, 0xc9, 0x21, 0x54 },
    .result = false /*F (3 - S changed) */
  },

  {
    .m = { 0x0a, 0x3a, 0x12, 0xc3, 0x08, 0x4c, 0x86, 0x5d,
           0xaf, 0x1d, 0x30, 0x2c, 0x78, 0x21, 0x5d, 0x39,
           0xbf, 0xe0, 0xb8, 0xbf, 0x28, 0x27, 0x2b, 0x3c,
           0x0b, 0x74, 0xbe, 0xb4, 0xb7, 0x40, 0x9d, 0xb0,
           0x71, 0x82, 0x39, 0xde, 0x70, 0x07, 0x85, 0x58,
           0x15, 0x14, 0x32, 0x1c, 0x64, 0x40, 0xa4, 0xbb,
           0xae, 0xa4, 0xc7, 0x6f, 0xa4, 0x74, 0x01, 0xe1,
           0x51, 0xe6, 0x8c, 0xb6, 0xc2, 0x90, 0x17, 0xf0,
           0xbc, 0xe4, 0x63, 0x12, 0x90, 0xaf, 0x5e, 0xa5,
           0xe2, 0xbf, 0x3e, 0xd7, 0x42, 0xae, 0x11, 0x0b,
           0x04, 0xad, 0xe8, 0x3a, 0x5d, 0xbd, 0x73, 0x58,
           0xf2, 0x9a, 0x85, 0x93, 0x8e, 0x23, 0xd8, 0x7a,
           0xc8, 0x23, 0x30, 0x72, 0xb7, 0x9c, 0x94, 0x67,
           0x0f, 0xf0, 0x95, 0x9f, 0x9c, 0x7f, 0x45, 0x17,
           0x86, 0x2f, 0xf8, 0x29, 0x45, 0x20, 0x96, 0xc7,
           0x8f, 0x5f, 0x2e, 0x9a, 0x7e, 0x4e, 0x92, 0x16 },
    .x = { 0x91, 0x57, 0xdb, 0xfc, 0xf8, 0xcf, 0x38, 0x5f,
           0x5b, 0xb1, 0x56, 0x8a, 0xd5, 0xc6, 0xe2, 0xa8,
           0x65, 0x2b, 0xa6, 0xdf, 0xc6, 0x3b, 0xc1, 0x75,
           0x3e, 0xdf, 0x52, 0x68, 0xcb, 0x7e, 0xb5, 0x96 },
    .y = { 0x97, 0x25, 0x70, 0xf4, 0x31, 0x3d, 0x47, 0xfc,
           0x96, 0xf7, 0xc0, 0x2d, 0x55, 0x94, 0xd7, 0x7d,
           0x46, 0xf9, 0x1e, 0x94, 0x98, 0x08, 0x82, 0x5b,
           0x3d, 0x31, 0xf0, 0x29, 0xe8, 0x29, 0x64, 0x05 },
    .r = { 0xdf, 0xae, 0xa6, 0xf2, 0x97, 0xfa, 0x32, 0x0b,
           0x70, 0x78, 0x66, 0x12, 0x5c, 0x2a, 0x7d, 0x5d,
           0x51, 0x5b, 0x51, 0xa5, 0x03, 0xbe, 0xe8, 0x17,
           0xde, 0x9f, 0xaa, 0x34, 0x3c, 0xc4, 0x8e, 0xeb },
    .s = { 0x8f, 0x78, 0x0a, 0xd7, 0x13, 0xf9, 0xc3, 0xe5,
           0xa4, 0xf7, 0xfa, 0x4c, 0x51, 0x98, 0x33, 0xdf,
           0xef, 0xc6, 0xa7, 0x43, 0x23, 0x89, 0xb1, 0xe4,
           0xaf, 0x46, 0x39, 0x61, 0xf0, 0x97, 0x64, 0xf2 },
    .result = false /*F (1 - Message changed) */
  },

  {
    .m = { 0x78, 0x5d, 0x07, 0xa3, 0xc5, 0x4f, 0x63, 0xdc,
           0xa1, 0x1f, 0x5d, 0x1a, 0x5f, 0x49, 0x6e, 0xe2,
           0xc2, 0xf9, 0x28, 0x8e, 0x55, 0x00, 0x7e, 0x66,
           0x6c, 0x78, 0xb0, 0x07, 0xd9, 0x5c, 0xc2, 0x85,
           0x81, 0xdc, 0xe5, 0x1f, 0x49, 0x0b, 0x30, 0xfa,
           0x73, 0xdc, 0x9e, 0x2d, 0x45, 0xd0, 0x75, 0xd7,
           0xe3, 0xa9, 0x5f, 0xb8, 0xa9, 0xe1, 0x46, 0x5a,
           0xd1, 0x91, 0x90, 0x41, 0x24, 0x16, 0x0b, 0x7c,
           0x60, 0xfa, 0x72, 0x0e, 0xf4, 0xef, 0x1c, 0x5d,
           0x29, 0x98, 0xf4, 0x05, 0x70, 0xae, 0x2a, 0x87,
           0x0e, 0xf3, 0xe8, 0x94, 0xc2, 0xbc, 0x61, 0x7d,
           0x8a, 0x1d, 0xc8, 0x5c, 0x3c, 0x55, 0x77, 0x49,
           0x28, 0xc3, 0x87, 0x89, 0xb4, 0xe6, 0x61, 0x34,
           0x9d, 0x3f, 0x84, 0xd2, 0x44, 0x1a, 0x3b, 0x85,
           0x6a, 0x76, 0x94, 0x9b, 0x9f, 0x1f, 0x80, 0xbc,
           0x16, 0x16, 0x48, 0xa1, 0xca, 0xd5, 0x58, 0x8e },
    .x = { 0x07, 0x2b, 0x10, 0xc0, 0x81, 0xa4, 0xc1, 0x71,
           0x3a, 0x29, 0x4f, 0x24, 0x8a, 0xef, 0x85, 0x0e,
           0x29, 0x79, 0x91, 0xac, 0xa4, 0x7f, 0xa9, 0x6a,
           0x74, 0x70, 0xab, 0xe3, 0xb8, 0xac, 0xfd, 0xda },
    .y = { 0x95, 0x81, 0x14, 0x5c, 0xca, 0x04, 0xa0, 0xfb,
           0x94, 0xce, 0xdc, 0xe7, 0x52, 0xc8, 0xf0, 0x37,
           0x08, 0x61, 0x91, 0x6d, 0x2a, 0x94, 0xe7, 0xc6,
           0x47, 0xc5, 0x37, 0x3c, 0xe6, 0xa4, 0xc8, 0xf5 },
    .r = { 0x09, 0xf5, 0x48, 0x3e, 0xcc, 0xec, 0x80, 0xf9,
           0xd1, 0x04, 0x81, 0x5a, 0x1b, 0xe9, 0xcc, 0x1a,
           0x8e, 0x5b, 0x12, 0xb6, 0xeb, 0x48, 0x2a, 0x65,
           0xc6, 0x90, 0x7b, 0x74, 0x80, 0xcf, 0x4f, 0x19 },
    .s = { 0xa4, 0xf9, 0x0e, 0x56, 0x0c, 0x5e, 0x4e, 0xb8,
           0x69, 0x6c, 0xb2, 0x76, 0xe5, 0x16, 0x5b, 0x6a,
           0x9d, 0x48, 0x63, 0x45, 0xde, 0xdf, 0xb0, 0x94,
           0xa7, 0x6e, 0x84, 0x42, 0xd0, 0x26, 0x37, 0x8d },
    .result = false /*F (4 - Q changed) */
  },

  {
    .m = { 0x76, 0xf9, 0x87, 0xec, 0x54, 0x48, 0xdd, 0x72,
           0x21, 0x9b, 0xd3, 0x0b, 0xf6, 0xb6, 0x6b, 0x07,
           0x75, 0xc8, 0x0b, 0x39, 0x48, 0x51, 0xa4, 0x3f,
           0xf1, 0xf5, 0x37, 0xf1, 0x40, 0xa6, 0xe7, 0x22,
           0x9e, 0xf8, 0xcd, 0x72, 0xad, 0x58, 0xb1, 0xd2,
           0xd2, 0x02, 0x98, 0x53, 0x9d, 0x63, 0x47, 0xdd,
           0x55, 0x98, 0x81, 0x2b, 0xc6, 0x53, 0x23, 0xac,
           0xea, 0xf0, 0x52, 0x28, 0xf7, 0x38, 0xb5, 0xad,
           0x3e, 0x8d, 0x9f, 0xe4, 0x10, 0x0f, 0xd7, 0x67,
           0xc2, 0xf0, 0x98, 0xc7, 0x7c, 0xb9, 0x9c, 0x29,
           0x92, 0x84, 0x3b, 0xa3, 0xee, 0xd9, 0x1d, 0x32,
           0x44, 0x4f, 0x3b, 0x6d, 0xb6, 0xcd, 0x21, 0x2d,
           0xd4, 0xe5, 0x60, 0x95, 0x48, 0xf4, 0xbb, 0x62,
           0x81, 0x2a, 0x92, 0x0f, 0x6e, 0x2b, 0xf1, 0x58,
           0x1b, 0xe1, 0xeb, 0xee, 0xbd, 0xd0, 0x6e, 0xc4,
           0xe9, 0x71, 0x86, 0x2c, 0xc4, 0x20, 0x55, 0xca },
    .x = { 0x09, 0x30, 0x8e, 0xa5, 0xbf, 0xad, 0x6e, 0x5a,
           0xdf, 0x40, 0x86, 0x34, 0xb3, 0xd5, 0xce, 0x92,
           0x40, 0xd3, 0x54, 0x42, 0xf7, 0xfe, 0x11, 0x64,
           0x52, 0xaa, 0xec, 0x0d, 0x25, 0xbe, 0x8c, 0x24 },
    .y = { 0xf4, 0x0c, 0x93, 0xe0, 0x23, 0xef, 0x49, 0x4b,
           0x1c, 0x30, 0x79, 0xb2, 0xd1, 0x0e, 0xf6, 0x7f,
           0x31, 0x70, 0x74, 0x04, 0x95, 0xce, 0x2c, 0xc5,
           0x7f, 0x8e, 0xe4, 0xb0, 0x61, 0x8b, 0x8e, 0xe5 },
    .r = { 0x5c, 0xc8, 0xaa, 0x7c, 0x35, 0x74, 0x3e, 0xc0,
           0xc2, 0x3d, 0xde, 0x88, 0xda, 0xbd, 0x5e, 0x4f,
           0xcd, 0x01, 0x92, 0xd2, 0x11, 0x6f, 0x69, 0x26,
           0xfe, 0xf7, 0x88, 0xcd, 0xdb, 0x75, 0x4e, 0x73 },
    .s = { 0x9c, 0x9c, 0x04, 0x5e, 0xba, 0xa1, 0xb8, 0x28,
           0xc3, 0x2f, 0x82, 0xac, 0xe0, 0xd1, 0x8d, 0xae,
           0xbf, 0x5e, 0x15, 0x6e, 0xb7, 0xcb, 0xfd, 0xc1,
           0xef, 0xf4, 0x39, 0x9a, 0x8a, 0x90, 0x0a, 0xe7 },
    .result = false /*F (1 - Message changed) */
  },

  {
    .m = { 0x60, 0xcd, 0x64, 0xb2, 0xcd, 0x2b, 0xe6, 0xc3,
           0x38, 0x59, 0xb9, 0x48, 0x75, 0x12, 0x03, 0x61,
           0xa2, 0x40, 0x85, 0xf3, 0x76, 0x5c, 0xb8, 0xb2,
           0xbf, 0x11, 0xe0, 0x26, 0xfa, 0x9d, 0x88, 0x55,
           0xdb, 0xe4, 0x35, 0xac, 0xf7, 0x88, 0x2e, 0x84,
           0xf3, 0xc7, 0x85, 0x7f, 0x96, 0xe2, 0xba, 0xab,
           0x4d, 0x9a, 0xfe, 0x45, 0x88, 0xe4, 0xa8, 0x2e,
           0x17, 0xa7, 0x88, 0x27, 0xbf, 0xdb, 0x5d, 0xdb,
           0xd1, 0xc2, 0x11, 0xfb, 0xc2, 0xe6, 0xd8, 0x84,
           0xcd, 0xdd, 0x7c, 0xb9, 0xd9, 0x0d, 0x5b, 0xf4,
           0xa7, 0x31, 0x1b, 0x83, 0xf3, 0x52, 0x50, 0x80,
           0x33, 0x81, 0x2c, 0x77, 0x6a, 0x0e, 0x00, 0xc0,
           0x03, 0xc7, 0xe0, 0xd6, 0x28, 0xe5, 0x07, 0x36,
           0xc7, 0x51, 0x2d, 0xf0, 0xac, 0xfa, 0x9f, 0x23,
           0x20, 0xbd, 0x10, 0x22, 0x29, 0xf4, 0x64, 0x95,
           0xae, 0x6d, 0x08, 0x57, 0xcc, 0x45, 0x2a, 0x84 },
    .x = { 0x2d, 0x98, 0xea, 0x01, 0xf7, 0x54, 0xd3, 0x4b,
           0xbc, 0x30, 0x03, 0xdf, 0x50, 0x50, 0x20, 0x0a,
           0xbf, 0x44, 0x5e, 0xc7, 0x28, 0x55, 0x6d, 0x7e,
           0xd7, 0xd5, 0xc5, 0x4c, 0x55, 0x55, 0x2b, 0x6d },
    .y = { 0x9b, 0x52, 0x67, 0x27, 0x42, 0xd6, 0x37, 0xa3,
           0x2a, 0xdd, 0x05, 0x6d, 0xfd, 0x6d, 0x87, 0x92,
           0xf2, 0xa3, 0x3c, 0x2e, 0x69, 0xda, 0xfa, 0xbe,
           0xa0, 0x9b, 0x96, 0x0b, 0xc6, 0x1e, 0x23, 0x0a },
    .r = { 0x06, 0x10, 0x8e, 0x52, 0x5f, 0x84, 0x5d, 0x01,
           0x55, 0xbf, 0x60, 0x19, 0x32, 0x22, 0xb3, 0x21,
           0x9c, 0x98, 0xe3, 0xd4, 0x94, 0x24, 0xc2, 0xfb,
           0x2a, 0x09, 0x87, 0xf8, 0x25, 0xc1, 0x79, 0x59 },
    .s = { 0x62, 0xb5, 0xcd, 0xd5, 0x91, 0xe5, 0xb5, 0x07,
           0xe5, 0x60, 0x16, 0x7b, 0xa8, 0xf6, 0xf7, 0xcd,
           0xa7, 0x46, 0x73, 0xeb, 0x31, 0x56, 0x80, 0xcb,
           0x89, 0xcc, 0xbc, 0x4e, 0xec, 0x47, 0x7d, 0xce },
    .result = true /*P (0 ) */
  }
};
/*---------------------------------------------------------------------------*/
PROCESS(ecdsa_verify_test, "ecdsa verify test");
AUTOSTART_PROCESSES(&ecdsa_verify_test);
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(ecdsa_verify_test, ev, data) {
  PROCESS_BEGIN();

  /*
   * Variable for Time Measurement
   */
  static rtimer_clock_t time;

  /*
   * Activate Engine
   */
  puts("-----------------------------------------\n"
       "Initializing pka...");
  pka_init();

  /*
   * Setup Variables
   */
  static ecc_dsa_verify_state_t state = {
    .process = &ecdsa_verify_test,
    .curve_info = &nist_p_256,
    .signature_r = { 0xC3B4035F, 0x515AD0A6, 0xBF375DCA, 0x0CC1E997,
                     0x7F54FDCD, 0x04D3FECA, 0xB9E396B9, 0x515C3D6E },
    .signature_s = { 0x5366B1AB, 0x0F1DBF46, 0xB0C8D3C4, 0xDB755B6F,
                     0xB9BF9243, 0xE644A8BE, 0x55159A59, 0x6F9E52A6 },
    .hash = { 0x65637572, 0x20612073, 0x68206F66, 0x20686173,
              0x69732061, 0x68697320, 0x6F2C2054, 0x48616C6C },
  };
  static uint32_t public_x[8] = { 0x5fa58f52, 0xe47cfbf2, 0x300c28c5, 0x6375ba10,
                                  0x62684e91, 0xda0a9a8f, 0xf9f2ed29, 0x36dfe2c6 };
  static uint32_t public_y[8] = { 0xc772f829, 0x4fabc36f, 0x09daed0b, 0xe93f9872,
                                  0x35a7cfab, 0x5a3c7869, 0xde1ab878, 0x71a0d4fc };

  memcpy(state.public.x, public_x, sizeof(public_x));
  memcpy(state.public.y, public_y, sizeof(public_y));

  /*
   * Verify
   */
  time = RTIMER_NOW();
  PT_SPAWN(&(ecdsa_verify_test.pt), &(state.pt), ecc_dsa_verify(&state));
  time = RTIMER_NOW() - time;
  printf("ecc_dsa_verify(), %" PRIu32 " ms\n",
         (uint32_t)((uint64_t)time * 1000 / RTIMER_SECOND));

  if(state.result) {
    printf("signature verification failed %d\n", state.result);
  } else {
    puts("signature verification OK");
  }

  /*
   * NIST tests
   */
  static int i;
  for(i = 0; i != 15; ++i) {
    printf("-----------------------------------------\n");
    printf("Starting test %d\n", i);

    uint8_t hash[32];
    SHA_256.hash(tests[i].m, sizeof(tests[i].m), hash);

    ec_uint8v_to_uint32v(state.public.x, tests[i].x, sizeof(tests[i].x));
    ec_uint8v_to_uint32v(state.public.y, tests[i].y, sizeof(tests[i].y));
    ec_uint8v_to_uint32v(state.signature_r, tests[i].r, sizeof(tests[i].r));
    ec_uint8v_to_uint32v(state.signature_s, tests[i].s, sizeof(tests[i].s));
    ec_uint8v_to_uint32v(state.hash, hash, sizeof(hash));

    /*
     * Verify
     */
    time = RTIMER_NOW();
    PT_SPAWN(&(ecdsa_verify_test.pt), &(state.pt), ecc_dsa_verify(&state));
    time = RTIMER_NOW() - time;
    printf("ecc_dsa_verify(), %" PRIu32 " ms\n",
           (uint32_t)((uint64_t)time * 1000 / RTIMER_SECOND));

    if(state.result == PKA_STATUS_SUCCESS && tests[i].result) {
      printf("[PASS] signature verification sucessful and expected %d\n",
             state.result);
    } else if(state.result == PKA_STATUS_SUCCESS && !tests[i].result) {
      printf("[FAIL] signature verification sucessful and unexpected %d\n",
             state.result);
    } else if(state.result != PKA_STATUS_SUCCESS && tests[i].result) {
      printf("[FAIL] signature verification unsucessful and unexpected %d\n",
             state.result);
    } else if(state.result != PKA_STATUS_SUCCESS && !tests[i].result) {
      printf("[PASS] signature verification unsucessful and expected %d\n",
             state.result);
    }
  }

  printf("-----------------------------------------\n");

  puts("Disabling pka...");
  pka_disable();

  puts("Done!");

  PROCESS_END();
}
/*---------------------------------------------------------------------------*/
/**
 * @}
 * @}
 */
